package com.daoyin.ssph.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.daoyin.ssph.bean.Application;

/**
 * A data access object (DAO) providing persistence and search support for
 * Application entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.daoyin.ssph.bean.Application
 * @author MyEclipse Persistence Tools
 */

public class ApplicationDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(ApplicationDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String AGE = "age";
	public static final String ADRESS = "adress";
	public static final String PHONE = "phone";
	public static final String EMAIL = "email";
	public static final String SCHOOL = "school";
	public static final String ZY = "zy";
	public static final String XL = "xl";
	public static final String COMPANY = "company";
	public static final String ZW = "zw";
	public static final String HY = "hy";
	public static final String MONEY = "money";
	public static final String QWHY = "qwhy";
	public static final String ACHADR = "achadr";
	public static final String JINENG = "jineng";

	protected void initDao() {
		// do nothing
	}

	public void save(Application transientInstance) {
		log.debug("saving Application instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Application persistentInstance) {
		log.debug("deleting Application instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Application findById(java.lang.Integer id) {
		log.debug("getting Application instance with id: " + id);
		try {
			Application instance = (Application) getHibernateTemplate().get(
					"com.daoyin.ssph.bean.Application", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Application instance) {
		log.debug("finding Application instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Application instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Application as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByAge(Object age) {
		return findByProperty(AGE, age);
	}

	public List findByAdress(Object adress) {
		return findByProperty(ADRESS, adress);
	}

	public List findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findBySchool(Object school) {
		return findByProperty(SCHOOL, school);
	}

	public List findByZy(Object zy) {
		return findByProperty(ZY, zy);
	}

	public List findByXl(Object xl) {
		return findByProperty(XL, xl);
	}

	public List findByCompany(Object company) {
		return findByProperty(COMPANY, company);
	}

	public List findByZw(Object zw) {
		return findByProperty(ZW, zw);
	}

	public List findByHy(Object hy) {
		return findByProperty(HY, hy);
	}

	public List findByMoney(Object money) {
		return findByProperty(MONEY, money);
	}

	public List findByQwhy(Object qwhy) {
		return findByProperty(QWHY, qwhy);
	}

	public List findByAchadr(Object achadr) {
		return findByProperty(ACHADR, achadr);
	}

	public List findByJineng(Object jineng) {
		return findByProperty(JINENG, jineng);
	}

	public List findAll() {
		log.debug("finding all Application instances");
		try {
			String queryString = "from Application";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Application merge(Application detachedInstance) {
		log.debug("merging Application instance");
		try {
			Application result = (Application) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Application instance) {
		log.debug("attaching dirty Application instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Application instance) {
		log.debug("attaching clean Application instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ApplicationDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (ApplicationDAO) ctx.getBean("ApplicationDAO");
	}
}